<%@ page import="com.h.heal.entity.Admin" %>
<%@ page import="com.h.heal.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>HEAL视频投稿</title>
    <jsp:include page="../../common_css.jsp"/>

    <style>
        .form-control {
            width: 30%;
        }
    </style>
</head>
<body style="background: linear-gradient(to top right, #a1ffce 0%, #faffd1 100%);">
<div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <jsp:include page="../../top_user.jsp"/>

    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
        <!-- partial:partials/_sidebar.html -->
        <jsp:include page="../../left_user.jsp"/>
        <!-- partial -->
        <div class="main-panel">
            <div class="row">
                <div class="col-md-12 stretch-card">
                    <div class="card"style="background: rgba(255,255,255,0);
    border: none;">
                        <div class="card-body">

                            <div class="table-responsive" align="center">


                                <form id="frm" class="form-signin">

                                    <h1 class="h3 mb-3 font-weight-normal">投稿视频</h1>
                                    <%--                                        <label for="input_product_id" class="sr-only">产品编号</label>--%>
                                    <%--                                        <input type="text" id="input_product_id" name="product_id" class="form-control" placeholder="产品编号" required autofocus>--%>


                                    <label for="input_video_vname" class="sr-only">视频标题</label>
                                    <input type="text" id="input_video_vname" name="video_vname" class="form-control"
                                           placeholder="视频标题">

                                    <label for="input_video_uid" class="sr-only">作者</label>
                                    <input type="text" id="input_video_uid" name="video_uid" class="form-control"
                                           placeholder="作者"
                                           value="<%=((User)request.getSession().getAttribute("user_info")).getUser_uid()%>"
                                           readonly>

                                    <label for="input_video_url" class="sr-only">视频URL</label>
                                    <input type="text" id="input_video_url" name="video_url" class="form-control"
                                           placeholder="视频URL">

                                    <label for="input_video_img" class="sr-only">视频封面</label>
                                    <input type="text" id="input_video_img" name="video_img" class="form-control"
                                           placeholder="视频封面">

                                    上传视频 <label for="input_video" class="sr-only">视频封面</label>
                                    <input type="file" accept="video/*" id="input_video" name="video"
                                           class="form-control"
                                           placeholder="上传视频">

                                    上传封面<label for="img" class="sr-only">上传封面</label>
                                    <input type="file" accept="image/*" id="img" name="img" class="form-control"
                                           placeholder="上传封面">


                                    <button class="btn btn-lg btn-primary btn-block" type="button" onclick="creat()"
                                            style="width: 30%">添加
                                    </button>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <jsp:include page="../../footer.jsp"/>
    </div>
    <!-- main-panel ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<jsp:include page="../../common_js.jsp"/>
</body>

</html>

<script>
    function creat() {
        //推荐前端js验证字段
        var video_vname = $("#input_video_vname").val();
        var video_uid = $("#input_video_uid").val();
        var video_url = $("#input_video_url").val();
        var video_img = $("#input_video_img").val();
        if (video_uid == null || video_uid == "" || video_vname == null || video_vname == "" || video_img == null || video_img == "") {
            alert("以上输入框不能为空");
        } else {
            var reg_uid = /^[0-9]*$/
            var reg_url = /https?:\/\/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/
            var reg_img = /https?:\/\/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/
            var reg_img = /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/

            if (!reg_url.test(video_url)) {
                alert("视频输入的URL有误");
            } else if (!reg_img.test(video_img)) {
                alert("图片输入的URL有误");
            } else if (!reg_uid.test(video_uid)) {
                alert("请输入纯数字的用户uid");
            } else {
                var input_product_id = $("#input_product_id").val();
                if (input_product_id == '') {
                    alert("产品编号不能为空");
                } else {
                    $.ajax(
                        {
                            type: "post",
                            url: "/video/creat",
                            data: $("#frm").serialize(),
                            async: false,  //使用ajax同步提交数据
                            success: function (response) {
                                if (response == "exist") {
                                    alert("添加失败，视频编号已经存在");
                                } else if (response == "ok") {
                                    alert("添加成功,1秒后跳转到视频列表");
                                    setTimeout(window.location.href = "/video/user/main", 500);
                                } else {
                                    alert("添加失败，请联系管理员....");
                                }
                            }
                        }
                    );
                }


            }


        }
    }
</script>

